﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using Southridge.Data;

namespace Southridge.View 
{
    
    public class PropertyTypetoBoolConverter : IValueConverter
    {

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {  
                if ( value != null && parameter != null ) 
                { 
                     
                    PropertyType propertyType = (PropertyType) Enum.Parse( typeof(PropertyType), value.ToString());
                    PropertyType param = (PropertyType) Enum.Parse(typeof(PropertyType), parameter.ToString());

                    return (propertyType & param ) != 0; 
                    
                }
            } finally {}  
            return false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                //if (value != null && parameter != null)
                //{
                //    bool boolValue = (bool)value;
                //    PropertyType param = (PropertyType)parameter;

                //    if ( boolValue ) 
                //    return (propertyType & param) != 0;

                //}
            }
            finally { }
            return false;
        }

        #endregion
    }
}
